<template>
  <div class="home">
    <a-button type="primary">fdsfsdfs</a-button>
    <router-link to="/">首页</router-link>

    <a-form
      ref="formRef"
      :model="formState"
      :rules="rules"
      :label-col="labelCol"
      :wrapper-col="wrapperCol"
    >
      <a-form-item label="账号" name="username">
        <a-input v-model:value="formState.username" />
      </a-form-item>
      <a-form-item label="密码" name="password">
        <a-input-password v-model:value="formState.password" />
      </a-form-item>

      <a-form-item :wrapper-col="{ span: 14, offset: 4 }">
        <a-button type="primary" @click="onSubmit">登录</a-button>
        <a-button style="margin-left: 10px" @click="resetForm">重置</a-button>
      </a-form-item>
    </a-form>

    <a-input v-model:value="item.name" />
    <a-input v-model:value="item.password" />
    <a-button type="primary" @click="doDo">登录并且生成拼争</a-button>

  </div>
</template>

<script>
import { defineComponent, reactive, ref, toRaw } from 'vue';
import { useRouter } from 'vue-router'
export default {
  name: 'Home',
  components: {
    
  },
  setup(){

    const formRef = ref();
    const router = useRouter()

    const item = reactive({})
    const doDo = () => {
      $g.get('/iscadapter/mock/makeTk/login').then(res => {

      }).catch(e => {
       
      })
    }


    const formState = reactive({
      username: undefined,
      password: undefined,
    });
    const rules = {
      username: {
        required: true,
        message: '请输入用户名',
      },
      password: [{
        required: true,
        message: '请输入密码',
      }]
    };

    const onSubmit = () => {
      formRef.value.validate().then(() => {
        $g.post('/basics/basics/account/encryptLogin', toRaw(formState)).then(res => {
          $g.setToken(res.body.token)
          router.push('/')
        }).catch(e => {
          console.log(e)
        })
      }).catch(error => {
        console.log('error', error);
      });
    };

    const resetForm = () => {
      formRef.value.resetFields();
    };

    return {
      item,
      doDo,
      formRef,
      labelCol: {
        span: 4,
      },
      wrapperCol: {
        span: 14,
      },
      formState,
      rules,
      onSubmit,
      resetForm,
    };

  }
}
</script>
